{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"read_pdf \n",
" Read and return text from PDF file with optional metadata.\n",
" \n",
" Args:\n",
" extract_metadata: Whether to include PDF metadata (default: False)\n",
" \n",
"scrape_url \n",
" Fetch and return cleaned text content from a webpage.\n",
" \n",
"crawl_site \n",
" Crawl a website starting from base_url and cache its text content in ChromaDB.\n",
" \n",
" Args:\n",
" base_url (str): Homepage URL of the website to crawl.\n",
" max_pages (int): Max number of pages to crawl (default: 20).\n",
" exclude_urls (list[str]): List of substrings/URLs to skip.\n",
" \n",
" Returns:\n",
" str: Number of pages successfully crawled and indexed.\n",
" \n",
"ask_site \n",
" Query across all crawled pages of the website.\n",
" \n",
" Args:\n",
" question (str): The natural language question to ask.\n",
" top_k (int): Number of top results to return (default: 3).\n",
" \n",
" Returns:\n",
" str: Relevant content snippets from the website.\n",
" \n",
"User: who is atul bansal ask_website\n",
"Calling tool ask_site with kwargs {'question': 'Atul Bansal', 'top_k': 3}\n",
"Tool ask_site returned meta=None content=[TextContent(type='text', text='[Result 1] https://www.velocis.in/products/compliance-engine\\nCompliance Engine | Velocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workpla...\\n\\n[Result 2] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 3] https://www.velocis.in/#contact-form\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n', annotations=None, meta=None)] structuredContent={'result': '[Result 1] https://www.velocis.in/products/compliance-engine\\nCompliance Engine | Velocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workpla...\\n\\n[Result 2] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 3] https://www.velocis.in/#contact-form\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n'} isError=False\n",
"Agent: Atul Bansal is the founder of Velocis, an Indian IT solutions company that provides various services including compliance engine, extended producer responsibility, and digital workplace solutions.\n",
"User: who is ashok gupta\n",
"Calling tool ask_site with kwargs {'question': 'Ashok Gupta', 'top_k': 3}\n",
"Tool ask_site returned meta=None content=[TextContent(type='text', text='[Result 1] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 2] https://www.velocis.in/\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n\\n[Result 3] https://www.velocis.in/#contact-form\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n', annotations=None, meta=None)] structuredContent={'result': '[Result 1] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 2] https://www.velocis.in/\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n\\n[Result 3] https://www.velocis.in/#contact-form\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n'} isError=False\n",
"Agent: I was unable to find any specific information on an individual named Ashok Gupta through my current resources. However, I can suggest some possible ways to find more information about him:\n",
"\n",
"1. Check the official website of Velocis: You can visit the official website of Velocis and see if they have any information about Ashok Gupta.\n",
"2. Search online: You can try searching for Ashok Gupta on search engines like Google, Bing, or Yahoo to see if any relevant results come up.\n",
"3. Check social media: You can try checking Ashok Gupta's social media profiles, such as LinkedIn, Twitter, or Facebook, to see if he has an official presence.\n",
"\n",
"I apologize for not being able to find more information about Ashok Gupta through my current resources. If you have any more specific information about him, I may be able to help you further.\n",
"User: who is ashok gupta from page about us\n",
"Calling tool ask_site with kwargs {'question': 'Ashok Gupta from page About us', 'top_k': 3}\n",
"Tool ask_site returned meta=None content=[TextContent(type='text', text='[Result 1] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 2] https://www.velocis.in/services/customer-experience-services\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n\\n[Result 3] https://www.velocis.in/services/managed-services\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n', annotations=None, meta=None)] structuredContent={'result': '[Result 1] https://www.velocis.in/extended-producer-responsibility\\nExtended Producer Responsibility WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Wo...\\n\\n[Result 2] https://www.velocis.in/services/customer-experience-services\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n\\n[Result 3] https://www.velocis.in/services/managed-services\\nVelocis WHO are we What we do Careers Events Insights Contact Us About us Meet our leaders Your trusted partner for IT solutions in India Leading system integrator, delivering future-ready technology competencies for business enhancement Meet our leaders Dedicated to driving innovation and growth across all channels, our leaders set high standards and inspire everyone to do their best work every day. Our domains Our products Our services Networks Cybersecurity Digital Workplace Data Centre and H...\\n'} isError=False\n",
"Agent: I was unable to find any information on Ashok Gupta from the page \"About Us\" through my current resources. However, I can suggest some possible ways to find more information about him:\n",
"\n",
"1. Check the official website of Velocis: You can visit the official website of Velocis and see if they have any information about Ashok Gupta.\n",
"2. Search online: You can try searching for Ashok Gupta on search engines like Google, Bing, or Yahoo to see if any relevant results come up.\n",
"\n",
"I apologize for not being able to find more information about Ashok Gupta through my current resources. If you have any more specific information about him, I may be able to help you further.\n",
"User: \n"
]
}
],
"source": [
"import nest_asyncio\n",
"nest_asyncio.apply()\n",
"\n",
"\n",
"from llama_index.llms.ollama import Ollama\n",
"from llama_index.core import Settings\n",
"\n",
"llm = Ollama(model=\"llama3.2:3b\", request_timeout=3600)\n",
"Settings.llm = llm\n",
"\n",
"\n",
"from llama_index.tools.mcp import BasicMCPClient, McpToolSpec\n",
"\n",
"mcp_client = BasicMCPClient(\"http://127.0.0.1:8000/sse\")\n",
"mcp_tools = McpToolSpec(client=mcp_client) # you can also pass list of allowed tools\n",
"\n",
"\n",
"tools = await mcp_tools.to_tool_list_async()\n",
"for tool in tools:\n",
" print(tool.metadata.name, tool.metadata.description)\n",
"\n",
"\n",
"\n",
" SYSTEM_PROMPT = \"\"\"\\\n",
"You are an AI assistant for Tool Calling.\n",
"\n",
"Before you help a user, you need to work with tools to interact with Our Database\n",
"\"\"\"\n",
"\n",
"\n",
"\n",
"from llama_index.tools.mcp import McpToolSpec\n",
"from llama_index.core.agent.workflow import FunctionAgent\n",
"\n",
"async def get_agent(tools: McpToolSpec):\n",
" tools = await tools.to_tool_list_async()\n",
" agent = FunctionAgent(\n",
" name=\"Agent\",\n",
" description=\"An agent that can work with Our Database software.\",\n",
" tools=tools,\n",
" llm=llm,\n",
" system_prompt=SYSTEM_PROMPT,\n",
" )\n",
" return agent\n",
"\n",
"\n",
"from llama_index.core.agent.workflow import (\n",
" FunctionAgent, \n",
" ToolCallResult, \n",
" ToolCall)\n",
"\n",
"from llama_index.core.workflow import Context\n",
"\n",
"async def handle_user_message(\n",
" message_content: str,\n",
" agent: FunctionAgent,\n",
" agent_context: Context,\n",
" verbose: bool = False,\n",
"):\n",
" handler = agent.run(message_content, ctx=agent_context)\n",
" async for event in handler.stream_events():\n",
" if verbose and type(event) == ToolCall:\n",
" print(f\"Calling tool {event.tool_name} with kwargs {event.tool_kwargs}\")\n",
" elif verbose and type(event) == ToolCallResult:\n",
" print(f\"Tool {event.tool_name} returned {event.tool_output}\")\n",
"\n",
" response = await handler\n",
" return str(response)\n",
"\n",
"\n",
"from llama_index.tools.mcp import BasicMCPClient, McpToolSpec\n",
"\n",
"\n",
"mcp_client = BasicMCPClient(\"http://127.0.0.1:8000/sse\")\n",
"mcp_tool = McpToolSpec(client=mcp_client)\n",
"\n",
"# get the agent\n",
"agent = await get_agent(mcp_tool)\n",
"\n",
"# create the agent context\n",
"agent_context = Context(agent)\n",
"\n",
"\n",
"\n",
"\n",
"# Run the agent!\n",
"while True:\n",
" user_input = input(\"Enter your message: \")\n",
" if user_input == \"exit\":\n",
" break\n",
" print(\"User: \", user_input)\n",
" response = await handle_user_message(user_input, agent, agent_context, verbose=True)\n",
" print(\"Agent: \", response)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}